﻿using System;
using System.Data;
using ContractManager.Common.Class;
using ContractManager.Common.FormBase;
using ContractManager.BLL.Business;

namespace ContractManager.Reports.TendersDocuments
{
    public partial class FrmBc14 : XtraFormBase
    {
        #region "Form Construction"
        public FrmBc14()
        {
            InitializeComponent();
        }
        #endregion

        #region "Private Method"

        private void BlankForm()
        {
            txtToDate.EditValue = DateTime.Now;
            
        }

        private void DoPerform()
        {
            
            string mbId = String.Format("{0}","");
            int conId = 0 ;
           
            ClsVariable.CreateWaitDialog(ClsVariable.StrCaption, "Vui lòng đợi...");
            ClsVariable.SetWaitDialogCaption("Đang nạp dữ liệu báo cáo...");

            DataTable dtReport = ClsReports.GetReportBc01(txtToDate.DateTime, txtToDate.DateTime,
                                                          mbId, this.StoreProcedureName, conId, "", "", "", ClsVariable.FullName, 0);
            grdReport.DataSource = dtReport;
            ClsVariable.CloseWaitDialog();
            if (!String.IsNullOrEmpty(FormReportLayoutTemplate))
            {
                string filePath = ClsVariable.GetRestoreLayoutFullPath(FormReportLayoutTemplate);
                grvReport.RestoreLayoutFromXml(filePath, DevExpress.Utils.OptionsLayoutBase.FullLayout);
            }
        }


        private void DoPrint()
        {
            string fileName = ReportName;
            string reportName = ClsVariable.GetReportFullPath(fileName);
            string mbId = String.Format("{0}", "");
            int conId = 0 ;
            var report = new Stimulsoft.Report.StiReport();
            report.Load(reportName);

            ClsVariable.CreateWaitDialog(ClsVariable.StrCaption, "Vui lòng đợi...");
            ClsVariable.SetWaitDialogCaption("Đang nạp dữ liệu báo cáo...");

            DataTable dtReport = ClsReports.GetReportBc01(txtToDate.DateTime, txtToDate.DateTime,
                                                          mbId, this.StoreProcedureName, conId,"","","","",0);
            report.RegData(dtReport);
            report.Compile();
            ClsVariable.CloseWaitDialog();
            // In thông tin đơn vị, địa chỉ

            report["KyBaoCao"] = String.Format("Đến ngày {0}", txtToDate.DateTime.ToString("dd/MM/yyyy"));

            ClsVariable.ApplyReportParam(report, ClsVariable.DtParam);
            report.Render(true);
            report.Show(this.MdiParent);
        }
        #endregion

        #region "Form Event"
        private void FrmBc14Load(object sender, EventArgs e)
        {
            BlankForm();
            DoPerform();
            if (!String.IsNullOrEmpty(FormXtraLayoutTemplate))
            {
                var fileLayout = ClsVariable.GetRestoreLayoutFullPath(FormXtraLayoutTemplate);
                layoutControl.RestoreLayoutFromXml(fileLayout);
            }
        }
        #endregion


        #region "Button Event"

        private void btnPrint_Click(object sender, EventArgs e)
        {
            DoPrint();
        }

        private void btnDesign_Click(object sender, EventArgs e)
        {
            ClsVariable.ShowDesignXtraGrid(grdReport);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

       

       

        

    }
}
